package com.tupi.project.component;

import com.tupi.project.base.App;
import com.tupi.project.util.CacheUtil;

import javax.inject.Inject;

/**
 * Created by Administrator on 2017/10/30.
 * 存储简单键值对
 */
public class PreferencesHelper implements PreferencesHelperInf
{
    private final CacheUtil mCache;
    
    private static final String SHAREDPREFERENCES_NAME = "my_sp";
    
    @Inject
    public PreferencesHelper()
    {
        mCache = CacheUtil.get(App.getInstance(), SHAREDPREFERENCES_NAME);
    }
    
    @Override
    public String getVersion()
    {
        return mCache.getAsString(Constants.SP_APP_VERSION, "1.0.0");
    }
    
    @Override
    public void setVersion(String version)
    {
        mCache.put(Constants.SP_APP_VERSION, version);
    }
    
    @Override
    public String getToken()
    {
        return mCache.getAsString(Constants.SP_TOKEN);
    }
    
    @Override
    public void setToken(String token)
    {
//        保存token一天
        mCache.put(Constants.SP_TOKEN, token, 60 * 60 * 24);
    }
    
}
